// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied.  See the License for the
// specific language governing permissions and limitations
// under the License.


suite("test_cast_to_double_from_datetimev2_0_part5") {

    // This test case is generated from the correspoinding be UT test case,
    // update this case if the correspoinding be UT test case is updated,
    // e.g.: ../run-be-ut.sh --run --filter=FunctionCastToDecimalTest.* --gen_regression_case
    sql "drop table if exists test_cast_to_double_from_datetimev2_0_part5_5_nullable;"
    sql "create table test_cast_to_double_from_datetimev2_0_part5_5_nullable(f1 int, f2 datetimev2(0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_double_from_datetimev2_0_part5_5_nullable values (0, "0100-01-01 00:00:01"),(1, "0100-01-01 00:00:01"),(2, "0100-01-01 00:00:01"),(3, "0100-01-01 00:00:59"),(4, "0100-01-01 00:00:59"),(5, "0100-01-01 00:00:59"),(6, "0100-01-01 00:01:00"),(7, "0100-01-01 00:01:00"),(8, "0100-01-01 00:01:00"),(9, "0100-01-01 00:01:01"),(10, "0100-01-01 00:01:01"),(11, "0100-01-01 00:01:01"),(12, "0100-01-01 00:01:59"),(13, "0100-01-01 00:01:59"),(14, "0100-01-01 00:01:59"),(15, "0100-01-01 00:59:00"),(16, "0100-01-01 00:59:00"),(17, "0100-01-01 00:59:00"),(18, "0100-01-01 00:59:01"),(19, "0100-01-01 00:59:01"),
      (20, "0100-01-01 00:59:01"),(21, "0100-01-01 00:59:59"),(22, "0100-01-01 00:59:59"),(23, "0100-01-01 00:59:59"),(24, "0100-01-01 01:00:00"),(25, "0100-01-01 01:00:00"),(26, "0100-01-01 01:00:00"),(27, "0100-01-01 01:00:01"),(28, "0100-01-01 01:00:01"),(29, "0100-01-01 01:00:01"),(30, "0100-01-01 01:00:59"),(31, "0100-01-01 01:00:59"),(32, "0100-01-01 01:00:59"),(33, "0100-01-01 01:01:00"),(34, "0100-01-01 01:01:00"),(35, "0100-01-01 01:01:00"),(36, "0100-01-01 01:01:01"),(37, "0100-01-01 01:01:01"),(38, "0100-01-01 01:01:01"),(39, "0100-01-01 01:01:59"),
      (40, "0100-01-01 01:01:59"),(41, "0100-01-01 01:01:59"),(42, "0100-01-01 01:59:00"),(43, "0100-01-01 01:59:00"),(44, "0100-01-01 01:59:00"),(45, "0100-01-01 01:59:01"),(46, "0100-01-01 01:59:01"),(47, "0100-01-01 01:59:01"),(48, "0100-01-01 01:59:59"),(49, "0100-01-01 01:59:59"),(50, "0100-01-01 01:59:59"),(51, "0100-01-01 23:00:00"),(52, "0100-01-01 23:00:00"),(53, "0100-01-01 23:00:00"),(54, "0100-01-01 23:00:01"),(55, "0100-01-01 23:00:01"),(56, "0100-01-01 23:00:01"),(57, "0100-01-01 23:00:59"),(58, "0100-01-01 23:00:59"),(59, "0100-01-01 23:00:59"),
      (60, "0100-01-01 23:01:00"),(61, "0100-01-01 23:01:00"),(62, "0100-01-01 23:01:00"),(63, "0100-01-01 23:01:01"),(64, "0100-01-01 23:01:01"),(65, "0100-01-01 23:01:01"),(66, "0100-01-01 23:01:59"),(67, "0100-01-01 23:01:59"),(68, "0100-01-01 23:01:59"),(69, "0100-01-01 23:59:00"),(70, "0100-01-01 23:59:00"),(71, "0100-01-01 23:59:00"),(72, "0100-01-01 23:59:01"),(73, "0100-01-01 23:59:01"),(74, "0100-01-01 23:59:01"),(75, "0100-01-01 23:59:59"),(76, "0100-01-01 23:59:59"),(77, "0100-01-01 23:59:59"),(78, "0100-01-28 00:00:00"),(79, "0100-01-28 00:00:00"),
      (80, "0100-01-28 00:00:00"),(81, "0100-01-28 00:00:01"),(82, "0100-01-28 00:00:01"),(83, "0100-01-28 00:00:01"),(84, "0100-01-28 00:00:59"),(85, "0100-01-28 00:00:59"),(86, "0100-01-28 00:00:59"),(87, "0100-01-28 00:01:00"),(88, "0100-01-28 00:01:00"),(89, "0100-01-28 00:01:00"),(90, "0100-01-28 00:01:01"),(91, "0100-01-28 00:01:01"),(92, "0100-01-28 00:01:01"),(93, "0100-01-28 00:01:59"),(94, "0100-01-28 00:01:59"),(95, "0100-01-28 00:01:59"),(96, "0100-01-28 00:59:00"),(97, "0100-01-28 00:59:00"),(98, "0100-01-28 00:59:00"),(99, "0100-01-28 00:59:01"),
      (100, "0100-01-28 00:59:01"),(101, "0100-01-28 00:59:01"),(102, "0100-01-28 00:59:59"),(103, "0100-01-28 00:59:59"),(104, "0100-01-28 00:59:59"),(105, "0100-01-28 01:00:00"),(106, "0100-01-28 01:00:00"),(107, "0100-01-28 01:00:00"),(108, "0100-01-28 01:00:01"),(109, "0100-01-28 01:00:01"),(110, "0100-01-28 01:00:01"),(111, "0100-01-28 01:00:59"),(112, "0100-01-28 01:00:59"),(113, "0100-01-28 01:00:59"),(114, "0100-01-28 01:01:00"),(115, "0100-01-28 01:01:00"),(116, "0100-01-28 01:01:00"),(117, "0100-01-28 01:01:01"),(118, "0100-01-28 01:01:01"),(119, "0100-01-28 01:01:01"),
      (120, "0100-01-28 01:01:59"),(121, "0100-01-28 01:01:59"),(122, "0100-01-28 01:01:59"),(123, "0100-01-28 01:59:00"),(124, "0100-01-28 01:59:00"),(125, "0100-01-28 01:59:00"),(126, "0100-01-28 01:59:01"),(127, "0100-01-28 01:59:01"),(128, "0100-01-28 01:59:01"),(129, "0100-01-28 01:59:59"),(130, "0100-01-28 01:59:59"),(131, "0100-01-28 01:59:59"),(132, "0100-01-28 23:00:00"),(133, "0100-01-28 23:00:00"),(134, "0100-01-28 23:00:00"),(135, "0100-01-28 23:00:01"),(136, "0100-01-28 23:00:01"),(137, "0100-01-28 23:00:01"),(138, "0100-01-28 23:00:59"),(139, "0100-01-28 23:00:59"),
      (140, "0100-01-28 23:00:59"),(141, "0100-01-28 23:01:00"),(142, "0100-01-28 23:01:00"),(143, "0100-01-28 23:01:00"),(144, "0100-01-28 23:01:01"),(145, "0100-01-28 23:01:01"),(146, "0100-01-28 23:01:01"),(147, "0100-01-28 23:01:59"),(148, "0100-01-28 23:01:59"),(149, "0100-01-28 23:01:59"),(150, "0100-01-28 23:59:00"),(151, "0100-01-28 23:59:00"),(152, "0100-01-28 23:59:00"),(153, "0100-01-28 23:59:01"),(154, "0100-01-28 23:59:01"),(155, "0100-01-28 23:59:01"),(156, "0100-01-28 23:59:59"),(157, "0100-01-28 23:59:59"),(158, "0100-01-28 23:59:59"),(159, "0100-12-01 00:00:00"),
      (160, "0100-12-01 00:00:00"),(161, "0100-12-01 00:00:00"),(162, "0100-12-01 00:00:01"),(163, "0100-12-01 00:00:01"),(164, "0100-12-01 00:00:01"),(165, "0100-12-01 00:00:59"),(166, "0100-12-01 00:00:59"),(167, "0100-12-01 00:00:59"),(168, "0100-12-01 00:01:00"),(169, "0100-12-01 00:01:00"),(170, "0100-12-01 00:01:00"),(171, "0100-12-01 00:01:01"),(172, "0100-12-01 00:01:01"),(173, "0100-12-01 00:01:01"),(174, "0100-12-01 00:01:59"),(175, "0100-12-01 00:01:59"),(176, "0100-12-01 00:01:59"),(177, "0100-12-01 00:59:00"),(178, "0100-12-01 00:59:00"),(179, "0100-12-01 00:59:00"),
      (180, "0100-12-01 00:59:01"),(181, "0100-12-01 00:59:01"),(182, "0100-12-01 00:59:01"),(183, "0100-12-01 00:59:59"),(184, "0100-12-01 00:59:59"),(185, "0100-12-01 00:59:59"),(186, "0100-12-01 01:00:00"),(187, "0100-12-01 01:00:00"),(188, "0100-12-01 01:00:00"),(189, "0100-12-01 01:00:01"),(190, "0100-12-01 01:00:01"),(191, "0100-12-01 01:00:01"),(192, "0100-12-01 01:00:59"),(193, "0100-12-01 01:00:59"),(194, "0100-12-01 01:00:59")
      ,(195, null);
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_0_part5_5_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_5_non_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_0_part5_5_nullable order by 1;'

    sql "drop table if exists test_cast_to_double_from_datetimev2_0_part5_5_not_nullable;"
    sql "create table test_cast_to_double_from_datetimev2_0_part5_5_not_nullable(f1 int, f2 datetimev2(0)) properties('replication_num'='1');"
    sql """insert into test_cast_to_double_from_datetimev2_0_part5_5_not_nullable values (0, "0100-01-01 00:00:01"),(1, "0100-01-01 00:00:01"),(2, "0100-01-01 00:00:01"),(3, "0100-01-01 00:00:59"),(4, "0100-01-01 00:00:59"),(5, "0100-01-01 00:00:59"),(6, "0100-01-01 00:01:00"),(7, "0100-01-01 00:01:00"),(8, "0100-01-01 00:01:00"),(9, "0100-01-01 00:01:01"),(10, "0100-01-01 00:01:01"),(11, "0100-01-01 00:01:01"),(12, "0100-01-01 00:01:59"),(13, "0100-01-01 00:01:59"),(14, "0100-01-01 00:01:59"),(15, "0100-01-01 00:59:00"),(16, "0100-01-01 00:59:00"),(17, "0100-01-01 00:59:00"),(18, "0100-01-01 00:59:01"),(19, "0100-01-01 00:59:01"),
      (20, "0100-01-01 00:59:01"),(21, "0100-01-01 00:59:59"),(22, "0100-01-01 00:59:59"),(23, "0100-01-01 00:59:59"),(24, "0100-01-01 01:00:00"),(25, "0100-01-01 01:00:00"),(26, "0100-01-01 01:00:00"),(27, "0100-01-01 01:00:01"),(28, "0100-01-01 01:00:01"),(29, "0100-01-01 01:00:01"),(30, "0100-01-01 01:00:59"),(31, "0100-01-01 01:00:59"),(32, "0100-01-01 01:00:59"),(33, "0100-01-01 01:01:00"),(34, "0100-01-01 01:01:00"),(35, "0100-01-01 01:01:00"),(36, "0100-01-01 01:01:01"),(37, "0100-01-01 01:01:01"),(38, "0100-01-01 01:01:01"),(39, "0100-01-01 01:01:59"),
      (40, "0100-01-01 01:01:59"),(41, "0100-01-01 01:01:59"),(42, "0100-01-01 01:59:00"),(43, "0100-01-01 01:59:00"),(44, "0100-01-01 01:59:00"),(45, "0100-01-01 01:59:01"),(46, "0100-01-01 01:59:01"),(47, "0100-01-01 01:59:01"),(48, "0100-01-01 01:59:59"),(49, "0100-01-01 01:59:59"),(50, "0100-01-01 01:59:59"),(51, "0100-01-01 23:00:00"),(52, "0100-01-01 23:00:00"),(53, "0100-01-01 23:00:00"),(54, "0100-01-01 23:00:01"),(55, "0100-01-01 23:00:01"),(56, "0100-01-01 23:00:01"),(57, "0100-01-01 23:00:59"),(58, "0100-01-01 23:00:59"),(59, "0100-01-01 23:00:59"),
      (60, "0100-01-01 23:01:00"),(61, "0100-01-01 23:01:00"),(62, "0100-01-01 23:01:00"),(63, "0100-01-01 23:01:01"),(64, "0100-01-01 23:01:01"),(65, "0100-01-01 23:01:01"),(66, "0100-01-01 23:01:59"),(67, "0100-01-01 23:01:59"),(68, "0100-01-01 23:01:59"),(69, "0100-01-01 23:59:00"),(70, "0100-01-01 23:59:00"),(71, "0100-01-01 23:59:00"),(72, "0100-01-01 23:59:01"),(73, "0100-01-01 23:59:01"),(74, "0100-01-01 23:59:01"),(75, "0100-01-01 23:59:59"),(76, "0100-01-01 23:59:59"),(77, "0100-01-01 23:59:59"),(78, "0100-01-28 00:00:00"),(79, "0100-01-28 00:00:00"),
      (80, "0100-01-28 00:00:00"),(81, "0100-01-28 00:00:01"),(82, "0100-01-28 00:00:01"),(83, "0100-01-28 00:00:01"),(84, "0100-01-28 00:00:59"),(85, "0100-01-28 00:00:59"),(86, "0100-01-28 00:00:59"),(87, "0100-01-28 00:01:00"),(88, "0100-01-28 00:01:00"),(89, "0100-01-28 00:01:00"),(90, "0100-01-28 00:01:01"),(91, "0100-01-28 00:01:01"),(92, "0100-01-28 00:01:01"),(93, "0100-01-28 00:01:59"),(94, "0100-01-28 00:01:59"),(95, "0100-01-28 00:01:59"),(96, "0100-01-28 00:59:00"),(97, "0100-01-28 00:59:00"),(98, "0100-01-28 00:59:00"),(99, "0100-01-28 00:59:01"),
      (100, "0100-01-28 00:59:01"),(101, "0100-01-28 00:59:01"),(102, "0100-01-28 00:59:59"),(103, "0100-01-28 00:59:59"),(104, "0100-01-28 00:59:59"),(105, "0100-01-28 01:00:00"),(106, "0100-01-28 01:00:00"),(107, "0100-01-28 01:00:00"),(108, "0100-01-28 01:00:01"),(109, "0100-01-28 01:00:01"),(110, "0100-01-28 01:00:01"),(111, "0100-01-28 01:00:59"),(112, "0100-01-28 01:00:59"),(113, "0100-01-28 01:00:59"),(114, "0100-01-28 01:01:00"),(115, "0100-01-28 01:01:00"),(116, "0100-01-28 01:01:00"),(117, "0100-01-28 01:01:01"),(118, "0100-01-28 01:01:01"),(119, "0100-01-28 01:01:01"),
      (120, "0100-01-28 01:01:59"),(121, "0100-01-28 01:01:59"),(122, "0100-01-28 01:01:59"),(123, "0100-01-28 01:59:00"),(124, "0100-01-28 01:59:00"),(125, "0100-01-28 01:59:00"),(126, "0100-01-28 01:59:01"),(127, "0100-01-28 01:59:01"),(128, "0100-01-28 01:59:01"),(129, "0100-01-28 01:59:59"),(130, "0100-01-28 01:59:59"),(131, "0100-01-28 01:59:59"),(132, "0100-01-28 23:00:00"),(133, "0100-01-28 23:00:00"),(134, "0100-01-28 23:00:00"),(135, "0100-01-28 23:00:01"),(136, "0100-01-28 23:00:01"),(137, "0100-01-28 23:00:01"),(138, "0100-01-28 23:00:59"),(139, "0100-01-28 23:00:59"),
      (140, "0100-01-28 23:00:59"),(141, "0100-01-28 23:01:00"),(142, "0100-01-28 23:01:00"),(143, "0100-01-28 23:01:00"),(144, "0100-01-28 23:01:01"),(145, "0100-01-28 23:01:01"),(146, "0100-01-28 23:01:01"),(147, "0100-01-28 23:01:59"),(148, "0100-01-28 23:01:59"),(149, "0100-01-28 23:01:59"),(150, "0100-01-28 23:59:00"),(151, "0100-01-28 23:59:00"),(152, "0100-01-28 23:59:00"),(153, "0100-01-28 23:59:01"),(154, "0100-01-28 23:59:01"),(155, "0100-01-28 23:59:01"),(156, "0100-01-28 23:59:59"),(157, "0100-01-28 23:59:59"),(158, "0100-01-28 23:59:59"),(159, "0100-12-01 00:00:00"),
      (160, "0100-12-01 00:00:00"),(161, "0100-12-01 00:00:00"),(162, "0100-12-01 00:00:01"),(163, "0100-12-01 00:00:01"),(164, "0100-12-01 00:00:01"),(165, "0100-12-01 00:00:59"),(166, "0100-12-01 00:00:59"),(167, "0100-12-01 00:00:59"),(168, "0100-12-01 00:01:00"),(169, "0100-12-01 00:01:00"),(170, "0100-12-01 00:01:00"),(171, "0100-12-01 00:01:01"),(172, "0100-12-01 00:01:01"),(173, "0100-12-01 00:01:01"),(174, "0100-12-01 00:01:59"),(175, "0100-12-01 00:01:59"),(176, "0100-12-01 00:01:59"),(177, "0100-12-01 00:59:00"),(178, "0100-12-01 00:59:00"),(179, "0100-12-01 00:59:00"),
      (180, "0100-12-01 00:59:01"),(181, "0100-12-01 00:59:01"),(182, "0100-12-01 00:59:01"),(183, "0100-12-01 00:59:59"),(184, "0100-12-01 00:59:59"),(185, "0100-12-01 00:59:59"),(186, "0100-12-01 01:00:00"),(187, "0100-12-01 01:00:00"),(188, "0100-12-01 01:00:00"),(189, "0100-12-01 01:00:01"),(190, "0100-12-01 01:00:01"),(191, "0100-12-01 01:00:01"),(192, "0100-12-01 01:00:59"),(193, "0100-12-01 01:00:59"),(194, "0100-12-01 01:00:59");
    """

    sql "set enable_strict_cast=true;"

    test {
        sql """select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_0_part5_5_not_nullable order by 1;"""
        exception ""
    }
    sql "set enable_strict_cast=false;"
    qt_sql_5_non_strict 'select f1, cast(f2 as double) from test_cast_to_double_from_datetimev2_0_part5_5_not_nullable order by 1;'

}